package com.njsoft.bodyawakening.table;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.njsoft.bodyawakening.R;
import com.njsoft.bodyawakening.table.adapter.CommonTabPagerAdapter;
import com.njsoft.bodyawakening.table.adapter.TableTimeAdapter;
import com.njsoft.bodyawakening.table.fragment.TableFragment;
import com.njsoft.bodyawakening.utils.TimeUtil;
import com.njsoft.bodyawakening.view.MyViewPager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TableActivity extends AppCompatActivity {

    @BindView(R.id.mTableTimeList)
    RecyclerView mTableTimeList;
    @BindView(R.id.mTableViewPager)
    MyViewPager mTableViewPager;
    private TableTimeAdapter adapter;
    private CommonTabPagerAdapter commonTabPagerAdapter;
    private int TimeListHeight;
    private int TimeListWhide;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_table);
        ButterKnife.bind(this);
        initRw();

        initViewpager();
    }

    private void initViewpager() {
        commonTabPagerAdapter = new CommonTabPagerAdapter(getSupportFragmentManager(), Arrays.asList("11", "22", "33"));
        mTableViewPager.setAdapter(commonTabPagerAdapter);
        commonTabPagerAdapter.setListener(new CommonTabPagerAdapter.TabPagerListener() {
            @Override
            public Fragment getFragment(int position) {
                return TableFragment.newInstance(TimeListWhide, TimeListHeight);
            }
        });
    }

    private void initRw() {
        ArrayList<String> timeList = TimeUtil.getListFormATimetoBtime(
                getString(R.string.BeginTime)
                , getString(R.string.EndTime),
                60 * 60 * 1000);
        adapter = new TableTimeAdapter(R.layout.time_item, timeList);
        mTableTimeList.setLayoutManager(new LinearLayoutManager(this));
        mTableTimeList.setAdapter(adapter);
        int w = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        int h = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        mTableTimeList.measure(w, h);
        TimeListHeight = mTableTimeList.getMeasuredHeight();
        TimeListWhide = mTableTimeList.getMeasuredWidth();

    }
}
